Stored Procedures [dbo].[asi_DocumentCreateShortcut]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@folderHierarchyKeyuniqueidentifier16
@documentVersionKeyuniqueidentifier16
@userKeyuniqueidentifier16
SQL Script
-- creates a shortcut to the document given by DocumentVersionKey
-- in the folder given by FolderHierarchyKey
CREATE PROCEDURE [dbo].[asi_DocumentCreateShortcut]
   @folderHierarchyKey uniqueidentifier,
   @documentVersionKey uniqueidentifier,
   @userKey uniqueidentifier
AS
BEGIN
   DECLARE @newDocumentKey uniqueidentifier, @newDocumentVersionKey uniqueidentifier, @documentKey uniqueidentifier

   SET @newDocumentKey = NewID()
   SET @newDocumentVersionKey = NewID()

   -- create the UniformRegistry entry first
   INSERT INTO UniformRegistry (UniformKey, ComponentKey)
   SELECT @newDocumentKey, ComponentKey
     FROM ComponentRegistry
    WHERE Name = 'Document'
      AND InterfaceName = 'BusinessController'

   -- then the UniformRegistry entry for the version key
   INSERT INTO UniformRegistry (UniformKey, ComponentKey)
   SELECT @newDocumentVersionKey, ComponentKey
     FROM ComponentRegistry
    WHERE Name = 'DocumentVersion'
      AND InterfaceName = 'BusinessController'

   -- make sure we get the latest one to shortcut to
   EXEC asi_DocumentGetLatestKey @documentVersionKey, @documentKey OUT

   -- then create the shortcut document
   INSERT INTO DocumentMain (
          DocumentKey,
          DocumentTypeCode,
          DocumentName,
          DocumentVersionKey,
          DocumentStatusCode,
          AlternateName,
          IsSystem,
          AccessKey,
          ContainsChildrenFlag,
          RelatedDocumentVersionKey,
          StatusUpdatedByUserKey,
          StatusUpdatedOn,
          UpdatedByUserKey,
          UpdatedOn,
          CreatedByUserKey,
          CreatedOn)
   SELECT @newDocumentKey,
          'SRT',
          DocumentName,
          @newDocumentVersionKey,
          40,
          AlternateName,
          0,
          AccessKey,
          0,
          @documentVersionKey,
          @userKey,
          GetDate(),
          @userKey,
          GetDate(),
          @userKey,
          GetDate()
     FROM DocumentMain
    WHERE DocumentKey = @documentKey

   -- if it worked, link it in.  If not, return null
   IF @@ROWCOUNT = 1
      exec asi_DocumentLinkDocument @folderHierarchyKey, @newDocumentVersionKey
   ELSE
      SELECT null
END

GO
Uses